package home_work7;

import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class test4 {

	public static void main(String[] args) throws ClassNotFoundException, IOException {
		test4 t = new test4();
		File dir = new File(".");
		List<Emp> list = t.loadEmps(dir);
		Collections.sort(list,new Comparator<Emp>(){
			public int compare(Emp e1, Emp e2) {				
				return e2.getSalary()-e1.getSalary();
			}			
		});
		for(Emp e : list){
			System.out.println(e);
		}
	}

	public List<Emp> loadEmps(File dir) throws ClassNotFoundException, IOException{
		List<Emp> list = new ArrayList<Emp>();
		File[] emps = dir.listFiles(new FileFilter(){
			public boolean accept(File file) {
				return file.getName().endsWith(".obj");
			}
			
		});
		for(File empFile : emps){
			Emp emp = loadEmp(empFile);
			list.add(emp);
		}
		return list;
	}

	public Emp loadEmp(File file) throws IOException, ClassNotFoundException{
		FileInputStream fis = new FileInputStream(file);
		ObjectInputStream ois = new ObjectInputStream(fis);
		Emp e = (Emp)ois.readObject();
		ois.close();
		return e;
	}
}
 
class AAA{
	public static void main(String[] args) {
		for(int i=1;i<=9;i++){
			for(int r=1;r<=i;r++){
				 System.out.print(r*i);
			}
			System.out.println();
		}

	}

}
